package cn.sourcespro.shiro.controller;

import cn.sourcespro.shiro.crudparams.dto.AddRoleDto;
import cn.sourcespro.shiro.crudparams.dto.AddUserRoleDto;
import cn.sourcespro.shiro.dao.UserRoleMapper;
import cn.sourcespro.shiro.entity.Role;
import cn.sourcespro.shiro.entity.UserRole;
import cn.sourcespro.shiro.service.RoleService;
import cn.sourcespro.shiro.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * security
 *
 * @author zhanghaowei
 * @date 2018/7/12
 */
@RestController
@RequestMapping("role")
public class UserRoleController {

    @Autowired
    private RoleService roleService;
    @Autowired
    private UserRoleService userRoleService;

    @PostMapping("add")
    String add(@RequestBody AddRoleDto roleDto){
        Role role = new Role();
        role.setName(roleDto.getName());
        role.setDescription(roleDto.getDescription());
        roleService.add(role);
        return "ok";
    }

    @PostMapping("bind")
    String bind(@RequestBody AddUserRoleDto roleDto){
        UserRole role = new UserRole();
        role.setUserId(roleDto.getUserId());
        role.setRoleId(roleDto.getRoleId());
        userRoleService.add(role);
        return "ok";
    }

}
